package com.cskaoyan.controller.admin;

//import com.cskaoyan.bean.MarketStorage;
//import com.cskaoyan.bean.common.BaseRespVo;
//import com.cskaoyan.service.admin.StorageService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.IOException;

///**
// * @Description
// * @Author klw
// * @Data 2022/11/19 下午5:44
// *
// * 图片上传
// */
//
//@RestController
//@RequestMapping("admin/storage")
//public class StorageController {
//
//    @Autowired
//    StorageService storageService;
//
//    @PostMapping("create")
//    public BaseRespVo create(MultipartFile file) throws IOException {
//        MarketStorage marketStorage = storageService.uploadFile(file);
//
//        return BaseRespVo.ok(marketStorage);
//    }
//}


import com.cskaoyan.bean.MarketStorage;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.admin.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author zjq
 * /admin/storage/*
 * @date 2022/11/20 17:07
 */
@RestController
@RequestMapping("/admin/storage")
public class StorageController {

    @Autowired
    StorageService storageService;

    @RequestMapping("/create")
    public BaseRespVo createFile(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        MarketStorage marketStorage = storageService.fileUpload(multipartFile);
        BaseRespVo ok = BaseRespVo.ok(marketStorage);
        return ok;
    }

    @RequestMapping("/list")
    public BaseRespVo getList(Integer page,Integer limit,String key,String name){
        CommonData commonData = storageService.getList(page, limit, key, name);
        BaseRespVo ok = BaseRespVo.ok(commonData);
        return ok;
    }
    @RequestMapping("/update")
    public BaseRespVo update(@RequestBody MarketStorage marketStorage){

        MarketStorage marketStorage1 = storageService.updateStorage(marketStorage);
        BaseRespVo ok = BaseRespVo.ok(marketStorage1);
        return ok;

    }

    @RequestMapping("/delete")
    public BaseRespVo delete(@RequestBody MarketStorage marketStorage){

        int i = storageService.deleteStorage(marketStorage);
        BaseRespVo ok = BaseRespVo.ok(null);
        return ok;
    }

}